﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;

namespace Model.WaiGaoQiao
{
    public class Work_Post_Relation
    {
        #region -------------  字段------------------------
        /// <summary>
        /// ID
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 岗位ID
        /// </summary>
        public int PostId { get; set; }
        /// <summary>
        /// 物品ID
        /// </summary>
        public int ArticleId { get; set; }
        /// <summary>
        /// 规则ID
        /// </summary>
        public int RuleId { get; set; }
        /// <summary>
        /// 领取数量
        /// </summary>
        public int GiveCount { get; set; }
        #endregion
        DataAccessWork_Post_Relation DAS;
        /// <summary>
        /// 行记录
        /// </summary>
        private int rowcount = 0;
        public int _rowcount
        {
            get { return rowcount; }
        }
        /// <summary>
        /// 是否获得行记录
        /// </summary>
        /// <param name="isGetCount"></param>
        public Work_Post_Relation(bool isGetCount)
        {
            DAS = new DataAccessWork_Post_Relation();
            if (isGetCount)
            {
                rowcount = DAS.GetWork_Post_RelationCount("");
            }

        }
        //构造函数
        public Work_Post_Relation() { }
        /// <summary>
        /// 获取劳防用品配置与发放标准数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_PostCount(string Condition)
        {
            string query = string.Empty;
            if (!string.IsNullOrEmpty(Condition))
                query = "AND postid in(select structrueid from StructureInformation_VIEW where structruename like '" + Condition + "%') ";
            return DAS.GetWork_Post_RelationCount(query);
        }


        /// <summary>
        /// 保存劳防用品配置与发放标准
        /// </summary>
        /// <param name="idab"></param>
        /// <returns></returns>
        public int SaveWork_Post(Work_Post_Relation sdiDetail)
        {
            object[] idpara = new object[] { sdiDetail.ID, sdiDetail.PostId, sdiDetail.ArticleId,sdiDetail.RuleId,sdiDetail.GiveCount};
            return DAS.SaveWork_Post_Relation(idpara);
        }

        /// <summary>
        /// 获取劳防用品配置与发放标准不分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Work_Post_Relation> GetAllPost(string condition)
        {
            
            IList<Work_Post_Relation> Idalist = new List<Work_Post_Relation>();
            DataSet ds = DAS.GetAllWork_Post_Relation(condition);
            Work_Post_Relation ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_Post_Relation()
                {
                    ID = Convert.ToInt32(item[0]),
                    PostId = Convert.ToInt32(item[1]),
                    ArticleId = Convert.ToInt32(item[2]),
                    RuleId = Convert.ToInt32(item[3]),
                    GiveCount = Convert.ToInt32(item[4]),
                   
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }


      

        /// <summary>
        /// 获取劳防用品配置与发放标准分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Work_Post_Relation> GetAllPost(string condition, int pagesize, int startindex)
        {
            IList<Work_Post_Relation> Idalist = new List<Work_Post_Relation>();
            string query = string.Empty;
            if (!string.IsNullOrEmpty(condition))
                query = "AND postid in(select structrueid from StructureInformation_VIEW where structruename like '" + condition + "%') ";
            DataSet ds = DAS.GetAllWork_Post_Relation(query, pagesize, startindex);
            Work_Post_Relation ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_Post_Relation()
                {
                    ID = Convert.ToInt32(item[0]),
                    PostId = Convert.ToInt32(item[1]),
                    ArticleId = Convert.ToInt32(item[2]),
                    RuleId = Convert.ToInt32(item[3]),
                    GiveCount = Convert.ToInt32(item[4]),
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }
        /// <summary>
        /// 根据ID获取劳防用品配置与发放标准实体类
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public Work_Post_Relation GetAllPost(int Id)
        {
            DataRow item = DAS.GetAllWork_Post_Relation(" And id=" + Id).Tables[0].Rows[0];
            Work_Post_Relation ideinfo = new Work_Post_Relation()
            {
                ID = Convert.ToInt32(item[0]),
                PostId = Convert.ToInt32(item[1]),
                ArticleId = Convert.ToInt32(item[2]),
                RuleId = Convert.ToInt32(item[3]),
                GiveCount = Convert.ToInt32(item[4])
            };
            return ideinfo;
        }


        /// <summary>
        /// 删除劳防用品配置与发放标准
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int DeletePost(string condition)
        {
            return DAS.DeleteWork_Post_Relation(condition);
        }



    }
    public class Work_post
    {
        DataAccessWork_Post_Relation DAS;
        /// <summary>
        /// StructrueId
        /// </summary>
        public int StructrueId { get; set; }
        /// <summary>
        /// 工种名称
        /// </summary>
        public string StructrueName { get; set; }
        public Work_post() 
        {
            DAS = new DataAccessWork_Post_Relation();
        }
        /// 根据条件获取所有岗位信息
        /// </summary>
        /// <returns></returns>
        public IList<Work_post> GetAllWork_Post(string condition)
        {
            IList<Work_post> Idalist = new List<Work_post>();
            DataSet ds = DAS.GetAllWork_Post(condition);
            Work_post ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_post()
                {
                    StructrueId = Convert.ToInt32(item[0]),
                    StructrueName = Convert.ToString(item[1]),
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }
        /// <summary>
        /// 根据条件获取所有岗位信息
        /// </summary>
        /// <returns></returns>
        public string GetPostName(int id)
        {
          DataTable dt=  DAS.GetPostName(id).Tables[0];
          if (dt != null && dt.Rows.Count > 0)
          {

              return dt.Rows[0][0].ToString();
          }
          else
          {
              return null;
          }
        }


    }
}
